/***************/
function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != "function"){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
/***********获取当前url****************/
/***************清除反应样式，当文档加入时执行******************/
/***
*a标签样式清除
**/
function deleteOnclick(){
	var eA = document.getElementsByClassName("rr")[0];
    eA.setAttribute("onclick","");
    return eA;
}
var eA = deleteOnclick();
/***
*input:text 样式去除（暂无）
***/

/**********写入预置HTML，文档加载时载入**************/
function innerDiv(){
	var clearDiv = document.createElement("div");
	clearDiv.setAttribute("class","clear");



    var pop_bg = document.createElement("div");
	pop_bg.setAttribute("id","pop_bg");
	pop_bg.setAttribute("class","pop_win_bg");
	document.body.appendChild(pop_bg);


	var pop = document.createElement("div");
	pop.setAttribute("class","pop_win");
	pop.setAttribute("id","pop");
	document.body.appendChild(pop);

	var pop_win_close = document.createElement("a");
	pop_win_close.setAttribute("class","pop_win_close");
	pop_win_close.setAttribute("id","pop_win_close");
	pop_win_close.setAttribute("href","");
	var pop_win_close_text = document.createTextNode("X");
	pop_win_close.appendChild(pop_win_close_text);
	pop.appendChild(pop_win_close);

	var searchForm = document.createElement("form");
	searchForm.setAttribute("id","searchForm");
	searchForm.setAttribute("action","");
	searchForm.setAttribute("method","get");
	var searchIcon = document.createElement("h1");
	searchIcon.setAttribute("id","searchText");
	var searchText = document.createTextNode("豆瓣读书");
	searchIcon.appendChild(searchText);
	searchForm.appendChild(searchIcon);
	var searchInput = document.createElement("input");
	searchInput.setAttribute("type","text");
	searchInput.setAttribute("id","searchInput");
	searchInput.setAttribute("value","URL、书名、作者、IBSN");
	searchForm.appendChild(searchInput);
	var searchSubmit = document.createElement("input");
	searchSubmit.setAttribute("type","submit");
	searchSubmit.setAttribute("id","searchSubmit");
	searchSubmit.setAttribute("value","搜索");
	searchForm.appendChild(searchSubmit);
	searchForm.appendChild(clearDiv);
	pop.appendChild(searchForm);

	pop.appendChild(clearDiv);
    
    var detailDiv = document.createElement("div");
   	detailDiv.setAttribute("id","detailDiv");
   	pop.appendChild(detailDiv);
    
    var annouceDiv = document.createElement("div");
    annouceDiv.setAttribute("id","annouceDiv");
    detailDiv.appendChild(annouceDiv);


	var searchResultsTextP = document.createElement("p");
	searchResultsTextP.setAttribute("id","searchResultsTextP");
	var searchResultsText = document.createTextNode("搜索结果");
	searchResultsTextP.appendChild(searchResultsText);
	annouceDiv.appendChild(searchResultsTextP);

	var upPage = document.createElement("a");
	upPage.setAttribute("id","upPage");
	upPageText = document.createTextNode("上一页");
	upPage.appendChild(upPageText);
	annouceDiv.appendChild(upPage);

	var downPage = document.createElement("a");
	downPage.setAttribute("id","downPage");
	downPageText = document.createTextNode("下一页");
	downPage.appendChild(downPageText);
	annouceDiv.appendChild(downPage);

	var urlAnode = document.createElement("a");
	urlAnode.setAttribute("id","urlAnode");
	urlAnodeText = document.createTextNode("点击提交豆列");
	urlAnode.appendChild(urlAnodeText);
	annouceDiv.appendChild(urlAnode);
	detailDiv.appendChild(clearDiv);

	/*********ajax detai*******/
	var ajaxDiv =document.createElement("div");
	ajaxDiv.setAttribute("id","ajaxDiv");
	detailDiv.appendChild(ajaxDiv);

};
addLoadEvent(innerDiv);


/**********动态显示***************/
function displayPop(){

	var pop = document.getElementById("pop");
	pop.style.top = "50%";
	pop.style.left = "50%";
	// pop.style.width = "300px";
	// pop.style.height = "200px";
	pop.style.visibility = "visible";
	pop.style.marginTop = "-212.5px";
	pop.style.marginLeft = "-219px";
	pop.style.zIndex = "9999";

	var pop_win_height = document.getElementById("pop").offsetHeight;
	var pop_bg = document.getElementById("pop_bg");
	pop_bg.style.top = "50%";
	pop_bg.style.left = "50%";
	pop_bg.style.width = "454px";
	pop_bg.style.height = (pop_win_height + 20) + "px";
	pop_bg.style.marginTop = "-220.5px";
	pop_bg.style.marginLeft = "-227px";
	pop_bg.style.zIndex = "8888";
	pop_bg.style.visibility = "visible";
}
// function addLoadEvent(){
eA.onclick = displayPop;
// }
// addLoadEvent(addLoadEvent);
function popWinClose(){
	var pop_bg = document.getElementById("pop_bg");
	pop_bg.style.visibility = "hidden";
	var pop = document.getElementById("pop");
	pop.style.visibility = "hidden";
	return false;

}
addLoadEvent(closePop);
function closePop(){
	var pop_win_close = document.getElementById("pop_win_close");
   	pop_win_close.onclick = popWinClose;
}

/*********为输入框添加文字**********/

function inputFocused(){
	   var searchInput = document.getElementById("searchInput");
		searchInput.setAttribute("value","");
		searchInput.style.color = "#000";
}
function inputBlured(){
	var searchInput = document.getElementById("searchInput");
	if(searchInput.value == ""){
		searchInput.setAttribute("value","URL、书名、作者、IBSN");
		searchInput.style.color = "#bbb";
	}	
}
function inputAdd(){
	var searchInput = document.getElementById("searchInput");
	searchInput.onfocus = inputFocused;
	searchInput.onblur = inputBlured;
}
addLoadEvent(inputAdd);

